<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数参数默认值</title>
  </head>

  <body>

  </body>
  <script>
    /* 
    函数参数的默认值
     */
    //1.在没有ES6之前，为了解决参数少传的问题，就是下面的写法
    function add(a, b, c, d) {
      a = a || 0;
      b = b || 0;
      c = c || 0;
      d = d || 0;
      return a + b + c + d;
    }
    console.log(add(10, 20)); //30

    //2.ES6的写法
    var func = function (a = 0, b = 0, c = 0, d = 0) {
      return a + b + c + d;
    }
    console.log(func(1, 2, 3)); //6
  </script>

</html>